Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tweenjs/tween.js

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tweenjs/tween.js

Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.

  • 17.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
228K
decreased by-63.07%
Maintainers
4
Weekly downloads
 
Created

What is @tweenjs/tween.js?

@tweenjs/tween.js is a simple but powerful tweening engine for JavaScript. It allows you to create smooth animations by interpolating between values over time. This can be used for animating properties of objects, such as position, scale, rotation, and more.

What are @tweenjs/tween.js's main functionalities?

Basic Tweening

This code demonstrates basic tweening where an object's properties (x and y coordinates) are animated from one state to another over a duration of 1000 milliseconds.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween = new TWEEN.Tween(coords)
  .to({ x: 100, y: 100 }, 1000)
  .onUpdate(() => {
    console.log(coords);
  })
  .start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Easing Functions

This code demonstrates the use of easing functions to create more natural motion. The Quadratic.Out easing function is used to slow down the animation towards the end.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween = new TWEEN.Tween(coords)
  .to({ x: 100, y: 100 }, 1000)
  .easing(TWEEN.Easing.Quadratic.Out)
  .onUpdate(() => {
    console.log(coords);
  })
  .start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Chaining Tweens

This code demonstrates chaining tweens, where one tween starts after another finishes. The x coordinate is animated first, followed by the y coordinate.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween1 = new TWEEN.Tween(coords)
  .to({ x: 100 }, 1000);
let tween2 = new TWEEN.Tween(coords)
  .to({ y: 100 }, 1000);

tween1.chain(tween2);
tween1.start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Other packages similar to @tweenjs/tween.js

Keywords

FAQs

Package last updated on 24 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc